package com.aisino.efence.task;

import com.aisino.efence.enums.FileEnum;
import com.aisino.efence.service.FileService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * @author fzc
 * @package com.aisino.efence.task
 * 数据同步线程
 * @create 2018-04-10 13:24
 **/
@Component
public class DataSyncTask {

    private static final Logger LOG = LoggerFactory.getLogger(DataSyncTask.class);

    @Autowired
    private FileService fileService;

    @Scheduled(fixedDelay = 30000)
    public void run() {

        LOG.info("[定时任务]-数据同步-开始执行");
        try {
            int i = fileService.hasFile();
            FileEnum fileEnum = FileEnum.getFileEnum(i);
            switch (fileEnum) {
                case EXIST:
                case ENCRYPT:
                case ZIP:
                    fileService.uploadFile();
                    fileService.sendMsg();
                    break;
                case UPLOAD:
                    fileService.sendMsg();
                    break;
                case MSG:
                    break;
                default:
                    break;
            }
            LOG.info("[定时任务]-数据同步-执行完毕");
        } catch (Exception e) {
            e.printStackTrace();
            LOG.error("[定时任务]-[error]-[{}]:", e);
        }

    }
}
